//
// Copyright (C) 2011 Cornell University, Department of Computer Science
//
// File Name: SessionTableEntry.java
// Author Name: Poornima Prabhu
// Date: 7:06:13 PM
package edu.cornell.cs.lsi.projone.model;

public class SessionTableData {

	/**
	 * flag to indicate if in use currently
	 */
	private boolean inUse;
	
	/**
	 * Session Id
	 */
	
	private String sessionID;
	/**
	 * Session version number
	 */
	private double versionNumber;
	/**
	 * Session creation time
	 */
	private String sessionCreationTime;
	/**
	 * Session value
	 */
	
	private String sessionVal;
	/**
	 * Counter - SessionValue
	 */
	private int counter;
	
	public int getCounter() {
		return counter;
	}

	public void setCounter(int count) {
		this.counter = count;
	}

	public String getSessionVal() {
		return sessionVal;
	}

	public void setSessionVal(String sessionVal) {
		this.sessionVal = sessionVal;
	}

	public String getSessionID() {
		return sessionID;
	}

	public void setSessionID(String sessionID) {
		this.sessionID = sessionID;
	}

	public double getVersionNumber() {
		return versionNumber;
	}

	public void setVersionNumber(double versionNumber) {
		this.versionNumber = versionNumber;
	}

	public String getSessionCreationTime() {
		return sessionCreationTime;
	}

	public void setSessionCreationTime(String sessionCreationTime) {
		this.sessionCreationTime = sessionCreationTime;
	}
	
	// returns true if one thread is updating an object of this class
	public boolean isInUse(){
		return this.inUse;
	}
	// synchronized update method 
	public void update(double versionId, String timestamp, int counter, String value){
		
		this.inUse = true;
		if(versionId != 0) this.versionNumber = versionId;
		if(timestamp!= null) this.sessionCreationTime = timestamp;
		if(counter != 0)this.counter = counter;
		if(value != null) this.sessionVal = value;
		this.inUse = false;
	}

}
